<?php

namespace app\controllers;


use app\models\Categories;
use app\models\Post;
use app\models\PostMeta;
use yii\web\NotFoundHttpException;

class VideoController extends PostController {

    public function actionDetail() {
        $id = $this->get('id');
        $where = is_numeric($id) ? ['id' => $id] : ['slug' => $id];

        $model = Post::findOne($where);
        if (!$model) {
            throw new NotFoundHttpException("post id: {$id} not found.");
        }

        $vod_list = PostMeta::find()->where(['post_id' => $model->id, 'type' => PostMeta::TYPE_VIDEO_URL])->select('name')->orderBy('id asc')->asArray()->all();

        $this->view->title = "{$model->slug} {$model->title}";
        $this->keywords = "{$model->slug},{$model->slug} BT,{$model->slug}下载,{$model->slug}迅雷";
        $this->description = $this->view->title;

        $view = '/' . Categories::$typeViews[$model->type] . '/detail';
        return $this->render(compact('model', 'vod_list'), $view);
    }

}